<?php
namespace app\wechat\controller\home;
use app\common\controller\Home;
use app\wechat\controller\Service;
use app\wechat\service\Official;
use EasyWeChat\Factory;
use think\Request;

class Index extends Home
{

    public $config;
    public function initialize()
    {
        parent::initialize();
        $this->config = [
            'app_id' => "wx2c904113419adbc1",
            "secret" => "040700095aa2336df8c068fddc3ddb0a",
            'response_type' => 'array',
        ];
    }

    //模板消息发送
    public function index(Request $request)
    {
        $type = $request->param("type",1,'intval');

        $user = get_weUser_thirdUser();
        $option = get_option("wechat_official");
        if(!empty($user['third_user']) && isset($user['third_user']['union_id']) && isset($option['official']) && $user['third_user']['app_id']==$option['official']['app_id'])
        {
        }
        /**
         *
        NS_8z65ePirM9jxwYbqVWAp9hbygO-in9E4pQ8maUYo
        {{first.DATA}}
        考试名称：{{keyword1.DATA}}
        考试时间：{{keyword2.DATA}}
        考试地点：{{keyword3.DATA}}
        考试科目：{{keyword4.DATA}}
        考试形式：{{keyword5.DATA}}
        {{remark.DATA}}
         */

        if($type==1)
        {
            //订阅通知
            $res = (new Official($this->config))->push_template_msg('oq8psuJqD-5pidJVWGqwpA4HfOIY','7-x3NkkwQ2Re_4q_dNt5xF0PbW4Euv3UXQlym9agtC8',[
                "first"=>"你已经成功订阅招考信息",
                "keyword1" => "你订阅贵阳招考信息",
                "keyword2" =>[
                    "value"=> "你订阅贵阳招考信息",
                    "color"=> "red"
                ]
            ]);
        }else{
            //考试通知
            $res = (new Official($this->config))->push_template_msg('oq8psuJqD-5pidJVWGqwpA4HfOIY','NS_8z65ePirM9jxwYbqVWAp9hbygO-in9E4pQ8maUYo',[
                "first"=>"三支一扶，考试通知",
                "keyword1" =>[
                    "value"=> "三支一扶",
                    "color"=> "red"
                ],
                "keyword2" =>[
                    "value"=> "你订阅贵阳招考信息",
                    "color"=> "red"
                ],
                "keyword3" =>[
                    "value"=> "见简章",
                    "color"=> "red"
                ],
                "keyword4" =>[
                    "value"=> "《综合应用能力》《申论》",
                    "color"=> "red"
                ],
                "keyword5" =>[
                    "value"=> "闭卷",
                    "color"=> "red"
                ],
                "remark"=>"请准时参加考试"
            ]);
        }

        dump($res);
    }


    public function prcode()
    {
        $res = (new Service())->get_prcode_url();
        echo "<img src='".$res."'/>";
    }

    public function wapoath()
    {
        $option = [
            'app_id' => 'wx022d032893708397',
            'secret' => 'eba61ec2a2aeae9bcc6e1d21c6e1e1ec'
        ];
        $res = (new Official($option))->get_token();
        dump($res);
    }
}